<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Locked demo</title>

  <link rel="stylesheet" href="demo.css"/>
  <script src="../dist/gridstack-all.js"></script>
  </style>
</head>
<body>
  <div class="container-fluid">
    <h1>Locked demo</h1>
    <div>
      <a class="btn btn-primary" onClick="addNewWidget()" href="#">Add Widget</a>
      <a class="btn btn-primary" onclick="toggleFloat()" id="float" href="#">float: true</a>
    </div>
    <br><br>
    <div class="grid-stack"></div>
  </div>

  <script type="text/javascript">
    let grid = GridStack.init({float: true});

    grid.on('added removed change', function(e, items) {
      let str = '';
      items.forEach(function(item) { str += ' (x,y)=' + item.x + ',' + item.y; });
      console.log(e.type + ' ' + items.length + ' items:' + str );
    });

    let items = [
      {x: 0, y: 1, w: 12, locked: 'yes', noMove: true, noResize: true, text: 'locked, noResize, noMove'},
      {x: 1, y: 0, w: 2, h: 3},
      {x: 4, y: 2},
      {x: 3, y: 1, h: 2},
      {x: 0, y: 6, w: 2, h: 2}
    ];
    let count = 0;

    addNewWidget = function() {
      let n = items[count] || {
        x: Math.round(12 * Math.random()),
        y: Math.round(5 * Math.random()),
        w: Math.round(1 + 3 * Math.random()),
        h: Math.round(1 + 3 * Math.random())
      };
      n.content = n.text ? n.text : String(count);
      grid.addWidget(n);
      count++
    };

    toggleFloat = function() {
      grid.float(! grid.float());
      document.querySelector('#float').innerHTML = 'float: ' + grid.float();
    };
    addNewWidget();
  </script>
</body>
</html>
